import { apiClient } from './client';
import { API_ENDPOINTS } from './config';
import type { Transaction, Refund } from '../../types/api';
import type { TransactionInfo } from '../../types/transaction';

export interface TransactionQueryParams {
  page: number;
  pageSize: number;
  startTime?: string;
  endTime?: string;
  cardId?: number;
  cardPosition?: string;
}

export const transactionApi = {
  getTransactions: async (params: TransactionQueryParams) => {
    return apiClient.get<{
      items: Transaction[];
      total: number;
      totalAmount: string;
    }>(API_ENDPOINTS.TRANSACTION_LIST, { params });
  },

  getRefunds: async (params: TransactionQueryParams) => {
    return apiClient.get<{
      items: Refund[];
      total: number;
      totalAmount: string;
    }>(API_ENDPOINTS.TRANSACTION_REFUNDS, { params });
  },

  getStats: async () => {
    return apiClient.get<TransactionInfo>(API_ENDPOINTS.TRANSACTION_STATS);
  },
};